package io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.light;

import io.gitee.yth.design.pattern.test.core.pattern.behavioral.command.Command;

/**
 * @author yth
 * @since 2023-04-28-23:21
 */
public class LightOffCommand implements Command {

    private boolean prefixState;
    private final LightReceiver lightReceiver;

    public LightOffCommand(LightReceiver lightReceiver) {
        this.lightReceiver = lightReceiver;
        this.prefixState = lightReceiver.isOn();
    }

    @Override
    public void execute() {
        prefixState = lightReceiver.isOn();
        System.out.println("execute 'light off' command ...");
        lightReceiver.off();
    }

    @Override
    public void undo() {
        System.out.println("undo 'light off' command ...");
        lightReceiver.setOn(prefixState);
    }
}
